const express = require('express');
const bodyParser = require('body-parser');
const app = express();

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));

app.get('/', (req, res, next) => {
	if (req.query.name != 'kivi') {
		res.send({
			error: true,
			message: 'no name',
			result: null
		});
	}
	else {
		res.send({
			error: false,
			message: null,
			result: 'hello world'
		});
	}
});

app.post('/', (req, res, next) => {
	if (req.body.name != 'kivi') {
		res.send({
			error: true,
			message: 'no name',
			result: null
		});
	}
	else {
		res.send({
			error: false,
			message: null,
			result: 'hello world'
		});
	}
});

app.put('/', (req, res, next) => {
	if (req.body.name != 'kivi') {
		res.send({
			error: true,
			message: 'no name',
			result: null
		});
	}
	else {
		res.send({
			error: false,
			message: null,
			result: 'hello world'
		});
	}
});

app.delete('/', (req, res, next) => {
	res.send({
		error: false,
		message: null,
		result: 'hello world'
	});
});


app.get('/error', (req, res, next) => {
	throw(new Error('hellow world'));
	res.send('hello world');
});

app.listen(3000, () => {
	console.log(`server is listening at 3000`);
});